package cn.yoyo.controller.cons;

import cn.yoyo.entity.User;
import cn.yoyo.service.UserService;
import cn.yoyo.tools.MySession;
import cn.yoyo.tools.RespJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Controller
@RequestMapping("/api/cons/user")
public class ConsUserController {
    @Autowired
    UserService userService;

    @RequestMapping("/go2Info")
    public String go2Info(){
        return "user/info";
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(User user, @RequestParam(value = "img",required = false)MultipartFile file){
        user.setId(MySession.getUserId());
        try {
            userService.update(user,file);
        } catch (Exception e){
            e.printStackTrace();
        }
        return RespJson.pack(200,"修改成功",null);
    }

}
